package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.LoadingZone;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

/* compiled from: Player.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/PlayerStanding.class */
public class PlayerStanding extends Action {
    public Action.Layer layer;
    public float initialWait;
    boolean alternate;
    boolean checkWildEncounter;
    boolean isRunning;
    Player player;
    public static int moveTimer = 0;
    public static int bTimer = 0;
    public int cTimer;
    public int vTimer;
    public Tile currTile;

    public PlayerStanding(Game game) {
        super(new Object[0]);
        this.layer = Action.Layer.map_130;
        this.checkWildEncounter = true;
        this.cTimer = 0;
        this.vTimer = 0;
        this.alternate = true;
        this.checkWildEncounter = false;
        this.isRunning = false;
        this.player = game.player;
    }

    public PlayerStanding(Game game, boolean alternate) {
        super(new Object[0]);
        this.layer = Action.Layer.map_130;
        this.checkWildEncounter = true;
        this.cTimer = 0;
        this.vTimer = 0;
        this.alternate = alternate;
        this.isRunning = false;
        this.player = game.player;
    }

    public PlayerStanding(Game game, boolean alternate, boolean isRunning) {
        super(new Object[0]);
        this.layer = Action.Layer.map_130;
        this.checkWildEncounter = true;
        this.cTimer = 0;
        this.vTimer = 0;
        this.alternate = alternate;
        this.isRunning = isRunning;
        this.player = game.player;
    }

    public PlayerStanding(Game game, Player player, boolean alternate, boolean isRunning) {
        super(new Object[0]);
        this.layer = Action.Layer.map_130;
        this.checkWildEncounter = true;
        this.cTimer = 0;
        this.vTimer = 0;
        this.alternate = alternate;
        this.isRunning = isRunning;
        this.checkWildEncounter = false;
        this.player = player;
    }

    boolean checkWildEncounter(Game game) {
        Pokemon pokemon = checkWildEncounter(game, game.player.position);
        if (pokemon != null) {
            game.battle.oppPokemon = pokemon;
        }
        return pokemon != null;
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(7:67|(2:132|69)(6:70|(1:72)|73|(1:75)(1:76)|77|(2:136|135))|107|81|134|(3:126|85|129)|135) */
    /* JADX WARNING: Code restructure failed: missing block: B:88:0x0321, code lost:
        if (com.corona.Game.rand.nextInt(256) >= 192) goto L_0x0324;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:89:0x0324, code lost:
        r17 = r0.get(r0);
        r16.evolveTo(r17);
        r19 = r19 + 1;
        r21 = false;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    com.corona.game.Pokemon checkWildEncounter(Game r7, Vector2 r8) {
        /*
        // Method dump skipped, instructions count: 1012
        */
        throw new UnsupportedOperationException("Method not decompiled: com.corona.game.PlayerStanding.checkWildEncounter(com.corona.Game, com.badlogic.gdx.math.Vector2):com.corona.game.Pokemon");
    }

    public void detectIsHouseBuilt(Game game, Tile currTile) {
        if (game.map.tiles == game.map.overworldTiles) {
            Vector2 pos = currTile.position.cpy();
            if (currTile.nameUpper.contains("house")) {
                Tile nextTile = currTile;
                Tile doorTile = null;
                boolean found = true;
                do {
                    if (nextTile.nameUpper.contains("middle") && !nextTile.nameUpper.contains("roof")) {
                        Tile tile = game.map.tiles.get(pos.add(0.0f, 16.0f));
                        while (true) {
                            Tile currTile2 = tile;
                            if (currTile2.nameUpper.contains("middle")) {
                                break;
                            } else if (!currTile2.nameUpper.contains("house")) {
                                found = false;
                                break;
                            } else {
                                tile = game.map.tiles.get(pos.add(0.0f, 16.0f));
                            }
                        }
                    }
                    if (nextTile.nameUpper.contains("door")) {
                        doorTile = nextTile;
                    }
                    if (!found || !nextTile.nameUpper.contains("house")) {
                        found = false;
                        break;
                    } else if (nextTile.nameUpper.contains("roof")) {
                        if (nextTile.nameUpper.contains("right")) {
                            nextTile = game.map.tiles.get(nextTile.position.cpy().add(0.0f, -16.0f));
                        } else {
                            nextTile = game.map.tiles.get(nextTile.position.cpy().add(16.0f, 0.0f));
                        }
                    } else if (nextTile.nameUpper.contains("left")) {
                        nextTile = game.map.tiles.get(nextTile.position.cpy().add(0.0f, 16.0f));
                    } else {
                        nextTile = game.map.tiles.get(nextTile.position.cpy().add(-16.0f, 0.0f));
                    }
                } while (!nextTile.equals(currTile));
                if (found) {
                    if (doorTile != null) {
                    }
                } else {
                    if (doorTile != null) {
                    }
                }
            }
        }
    }

    public void localStep(Game game) {
        String awayDir;
        Tile aboveTile;
        Action action;
        int downUp;
        if (game.playerCanMove) {
            boolean shouldMove = false;
            Vector2 newPos = new Vector2();
            if (this.checkWildEncounter) {
                game.player.updateBuildTiles(game);
                Tile tile = game.map.tiles.get(game.player.position);
                if (tile == null || (!tile.nameUpper.contains("stairs") && !tile.name.contains("stairs"))) {
                    game.player.eggStepTimer++;
                    game.player.friendshipStepTimer++;
                    if (Gdx.input.isKeyPressed(62) && game.dangerousDebugInputEnabled) {
                        game.player.eggStepTimer += 16;
                        game.player.friendshipStepTimer += 512;
                    }
                    if (game.player.eggStepTimer >= 16) {
                        Iterator<Pokemon> it = game.player.pokemon.iterator();
                        while (it.hasNext()) {
                            Pokemon pokemon = it.next();
                            if (pokemon.isEgg) {
                                pokemon.happiness--;
                                System.out.println(pokemon.nickname);
                                System.out.println(pokemon.specie.name);
                                System.out.println(pokemon.happiness);
                                if (pokemon.happiness <= 0) {
                                    game.playerCanMove = false;
                                    String[] huhs = {"Huh?", "Oh?"};
                                    game.insertAction(new WaitFrames(game, 61, new WaitFrames(game, 3, new DisplayText(game, huhs[Game.rand.nextInt(huhs.length)], (String) null, true, false, (Action) new WaitFrames(game, 51, new DisplayText.Clear(game, new EggHatchAnim(pokemon, new SplitAction(new SetField(game.musicController, "startEvolveMusic", true, null), new Battle.LoadAndPlayAnimation(game, "egg_hatch", null, new SplitAction(new WaitFrames(game, 4, new PlayMusic(new Pokemon(pokemon.specie.name, 10), (Action) null)), new PokemonIntroAnim(new WaitFrames(game, 4, new DisplayText(game, pokemon.getNickname().toUpperCase(Locale.ROOT) + " came out of its EGG!", "fanfare2.ogg", false, true, (Action) new SplitAction(new EggHatchAnim.Done(13, new SetField(game.musicController, "evolveMusicFadeout", true, null)), new WaitFrames(game, 13, new EnterBuilding(game, "", 8, new SetField(game, "playerCanMove", true, null)))))))))))))))));
                                    this.checkWildEncounter = false;
                                    return;
                                }
                            }
                        }
                        game.player.eggStepTimer = 0;
                    }
                    if (game.player.friendshipStepTimer >= 512) {
                        Iterator<Pokemon> it2 = game.player.pokemon.iterator();
                        while (it2.hasNext()) {
                            Pokemon pokemon2 = it2.next();
                            if (!pokemon2.isEgg) {
                                pokemon2.gainHappiness(1);
                                System.out.println(pokemon2.nickname);
                                System.out.println(pokemon2.happiness);
                            }
                        }
                        game.player.friendshipStepTimer = 0;
                    }
                } else {
                    if (tile.nameUpper.contains("up") || tile.name.contains("up")) {
                        downUp = 1;
                    } else {
                        downUp = -1;
                    }
                    game.playerCanMove = false;
                    Map<Vector2, Tile> whichTiles = game.map.interiorTiles.get(game.map.interiorTilesIndex + downUp);
                    if (tile.name.contains("exit") || tile.nameUpper.contains("exit")) {
                        whichTiles = game.map.overworldTiles;
                    }
                    game.insertAction(new EnterBuilding(game, "enter", whichTiles, game.map.interiorTilesIndex + downUp, new SetField(game.map, "interiorTilesIndex", Integer.valueOf(game.map.interiorTilesIndex + downUp), new SetField(game, "playerCanMove", true, null))));
                    this.checkWildEncounter = false;
                    return;
                }
            }
            if (this.checkWildEncounter && game.type != Game.Type.CLIENT) {
                if (checkWildEncounter(game)) {
                    this.player.setCurrPokemon();
                    if (!((game.player.repelCounter > 0 && game.battle.oppPokemon.level < game.player.currPokemon.level) || (game.player.hmPokemon != null && game.player.currFieldMove.equals("REPEL") && game.battle.oppPokemon.level < game.player.hmPokemon.level))) {
                        game.playerCanMove = false;
                        game.musicController.startBattle = "wild";
                        if (game.musicController.unownMusic) {
                            game.battle.oppPokemon = new Pokemon("unown_" + game.map.unownUsed.get(game.map.rand.nextInt(game.map.unownUsed.size())), 13);
                        }
                        game.insertAction(Battle.getIntroAction(game));
                        this.checkWildEncounter = false;
                        return;
                    }
                }
                if (game.player.repelCounter > 0) {
                    game.player.repelCounter--;
                    if (game.player.repelCounter == 0) {
                        game.playerCanMove = false;
                        game.insertAction(new DisplayText(game, "The effects of REPEL wore off.", (String) null, (Action) null, new WaitFrames(game, 3, new SetField(game, "playerCanMove", true, null))));
                        return;
                    }
                }
                this.checkWildEncounter = false;
            } else if (this.player.network.doEncounter != null) {
                this.player.setCurrPokemon();
                game.playerCanMove = false;
                Network.PokemonData pokemonData = this.player.network.doEncounter.pokemonData;
                game.battle.oppPokemon = new Pokemon(pokemonData.name, pokemonData.level);
                game.battle.oppPokemon.currentStats.put("hp", Integer.valueOf(pokemonData.hp));
                game.musicController.startBattle = "wild";
                game.insertAction(Battle.getIntroAction(game));
                this.checkWildEncounter = false;
                this.player.network.doEncounter = null;
                return;
            }
            if (game.map.tiles.get(game.player.position) != null && (game.map.tiles.get(game.player.position).nameUpper.contains("door") || game.map.tiles.get(game.player.position).name.contains("door"))) {
                game.playerCanMove = false;
                if (game.map.tiles == game.map.overworldTiles) {
                    action = new EnterBuilding(game, new SetField(game, "playerCanMove", true, null));
                } else {
                    action = new EnterBuilding(game, "exit", new SetField(game, "playerCanMove", true, null));
                }
                game.insertAction(action);
            } else if (game.player.acceptInput || game.player.isSleeping) {
                if (InputProcessor.startJustPressed) {
                    game.insertAction(new DrawPlayerMenu.Intro(game, new DrawPlayerMenu(game, new WaitFrames(game, 1, new SetField(game, "playerCanMove", true, null)))));
                    game.playerCanMove = false;
                } else if (!game.player.isSleeping) {
                    this.currTile = game.map.tiles.get(game.player.position);
                    if (this.currTile != null && this.currTile.name.equals("ice2")) {
                        Vector2 targetPos = game.player.facingPos();
                        Tile nextTile = game.map.tiles.get(targetPos);
                        boolean isSolid = (nextTile == null) | (nextTile != null && nextTile.isSolid) | (game.map.pokemon.get(targetPos) != null);
                        if (nextTile == null || nextTile.ledgeDir == null) {
                            if (this.currTile.ledgeDir().equals("up") && game.player.dirFacing.equals("up")) {
                                game.actionStack.remove(this);
                                game.insertAction(new PlayerLedgeJumpFast(game));
                                return;
                            } else if (!isSolid) {
                                game.actionStack.remove(this);
                                Player player = game.player;
                                Objects.requireNonNull(player);
                                game.insertAction(new Player.Sliding(this));
                                return;
                            }
                        } else if (!nextTile.ledgeDir.equals("up") && nextTile.ledgeDir.equals(game.player.dirFacing)) {
                            Tile fartherOutTile = game.map.tiles.get(targetPos.cpy().add(targetPos.cpy().sub(game.player.position)));
                            if (fartherOutTile != null && !fartherOutTile.isSolid && fartherOutTile.ledgeDir == null) {
                                game.actionStack.remove(this);
                                game.insertAction(new PlayerLedgeJump(game));
                                return;
                            }
                        } else if (nextTile.ledgeDir.equals("up") && !game.player.dirFacing.equals("down")) {
                            game.actionStack.remove(this);
                            Player player2 = game.player;
                            Objects.requireNonNull(player2);
                            game.insertAction(new Player.Sliding(this));
                            return;
                        }
                    }
                    if (InputProcessor.upPressed) {
                        game.player.dirFacing = "up";
                        newPos = new Vector2(game.player.position.x, game.player.position.y + 16.0f);
                        if (moveTimer == 0) {
                            game.player.updateBuildTiles(game);
                        } else if (moveTimer > 3) {
                            shouldMove = true;
                        }
                        moveTimer++;
                    } else if (InputProcessor.downPressed) {
                        game.player.dirFacing = "down";
                        newPos = new Vector2(game.player.position.x, game.player.position.y - 16.0f);
                        if (moveTimer == 0) {
                            game.player.updateBuildTiles(game);
                        } else if (moveTimer > 3) {
                            shouldMove = true;
                        }
                        moveTimer++;
                    } else if (InputProcessor.leftPressed) {
                        game.player.dirFacing = "left";
                        newPos = new Vector2(game.player.position.x - 16.0f, game.player.position.y);
                        if (moveTimer == 0) {
                            game.player.updateBuildTiles(game);
                        } else if (moveTimer > 3) {
                            shouldMove = true;
                        }
                        moveTimer++;
                    } else if (InputProcessor.rightPressed) {
                        game.player.dirFacing = "right";
                        newPos = new Vector2(game.player.position.x + 16.0f, game.player.position.y);
                        if (moveTimer == 0) {
                            game.player.updateBuildTiles(game);
                        } else if (moveTimer > 3) {
                            shouldMove = true;
                        }
                        moveTimer++;
                    } else {
                        moveTimer = 0;
                    }
                    if (game.player.currFieldMove.equals("BUILD") || game.player.currFieldMove.equals("DIG")) {
                        if (!InputProcessor.lPressed) {
                            this.cTimer = 0;
                        } else if (this.cTimer < 30) {
                            this.cTimer++;
                        }
                        if (!InputProcessor.rPressed) {
                            this.vTimer = 0;
                        } else if (this.vTimer < 30) {
                            this.vTimer++;
                        }
                    }
                    if (InputProcessor.lJustPressed || this.cTimer >= 30) {
                        if (game.player.currFieldMove.equals("BUILD")) {
                            game.player.buildTileIndex--;
                            if (game.player.buildTileIndex < 0) {
                                game.player.buildTileIndex = game.player.buildTiles.size() - 1;
                            }
                            game.player.currBuildTile = game.player.buildTiles.get(game.player.buildTileIndex);
                        } else if (game.player.currFieldMove.equals("DIG") && !game.player.currBuildTile.name.contains("hole")) {
                            do {
                                game.player.buildTileIndex--;
                                if (game.player.buildTileIndex < 0) {
                                    game.player.buildTileIndex = game.player.terrainTiles.size() - 1;
                                }
                                game.player.currBuildTile = game.player.terrainTiles.get(game.player.buildTileIndex);
                                boolean requirementsMet = true;
                                Iterator<String> it3 = game.player.buildTileRequirements.get(game.player.currBuildTile.name).keySet().iterator();
                                while (true) {
                                    if (!it3.hasNext()) {
                                        break;
                                    }
                                    String reqName = it3.next();
                                    if (game.player.hasItem(reqName)) {
                                        if (game.player.getItemAmount(reqName).intValue() < game.player.buildTileRequirements.get(game.player.currBuildTile.name).get(reqName).intValue()) {
                                            requirementsMet = false;
                                            break;
                                        }
                                    } else {
                                        requirementsMet = false;
                                        break;
                                    }
                                }
                                if (requirementsMet) {
                                    break;
                                }
                            } while (game.player.buildTileIndex != 0);
                        }
                    }
                    if (InputProcessor.rJustPressed || this.vTimer >= 30) {
                        if (game.player.currFieldMove.equals("BUILD")) {
                            game.player.buildTileIndex++;
                            if (game.player.buildTileIndex >= game.player.buildTiles.size()) {
                                game.player.buildTileIndex = 0;
                            }
                            game.player.currBuildTile = game.player.buildTiles.get(game.player.buildTileIndex);
                        } else if (game.player.currFieldMove.equals("DIG") && !game.player.currBuildTile.name.contains("hole")) {
                            do {
                                game.player.buildTileIndex++;
                                if (game.player.buildTileIndex >= game.player.terrainTiles.size()) {
                                    game.player.buildTileIndex = 0;
                                }
                                game.player.currBuildTile = game.player.terrainTiles.get(game.player.buildTileIndex);
                                boolean requirementsMet2 = true;
                                Iterator<String> it4 = game.player.buildTileRequirements.get(game.player.currBuildTile.name).keySet().iterator();
                                while (true) {
                                    if (!it4.hasNext()) {
                                        break;
                                    }
                                    String reqName2 = it4.next();
                                    if (game.player.hasItem(reqName2)) {
                                        if (game.player.getItemAmount(reqName2).intValue() < game.player.buildTileRequirements.get(game.player.currBuildTile.name).get(reqName2).intValue()) {
                                            requirementsMet2 = false;
                                            break;
                                        }
                                    } else {
                                        requirementsMet2 = false;
                                        break;
                                    }
                                }
                                if (requirementsMet2) {
                                    break;
                                }
                            } while (game.player.buildTileIndex != 0);
                        }
                    }
                    if (InputProcessor.bJustPressed) {
                        bTimer = 0;
                    }
                    if (shouldMove) {
                        bTimer = 20;
                    }
                    if (InputProcessor.bPressed) {
                        if (bTimer == 19) {
                            if (game.type == Game.Type.CLIENT && !game.player.currFieldMove.equals("")) {
                                game.client.sendTCP(new Network.UseHM(game.player.network.id, DrawPokemonMenu.currIndex, "STOP"));
                            }
                            if (game.player.currPlanting != null) {
                                game.player.currPlanting = null;
                                bTimer = 0;
                                return;
                            } else if (!game.player.currRod.equals("")) {
                                game.player.currRod = "";
                                bTimer = 0;
                                return;
                            } else if (game.player.hmPokemon != null && !game.player.currFieldMove.equals("SURF")) {
                                if (game.player.currFieldMove.equals("RIDE")) {
                                    game.player.swapSprites(game.player.hmPokemon);
                                    game.player.hmPokemon = null;
                                    game.player.currFieldMove = "";
                                } else {
                                    game.playerCanMove = false;
                                    game.actionStack.remove(game.player.hmPokemon.standingAction);
                                    if (game.player.hmPokemon.ledgeJumps.size() > 0) {
                                        Pokemon pokemon3 = game.player.hmPokemon;
                                        Pokemon pokemon4 = game.player.hmPokemon;
                                        Objects.requireNonNull(pokemon4);
                                        pokemon3.standingAction = new Pokemon.LedgeJump(game.player.hmPokemon.dirFacing, game.player.hmPokemon.ledgeJumps.remove(0).intValue(), true, null);
                                    } else {
                                        Pokemon pokemon5 = game.player.hmPokemon;
                                        Pokemon pokemon6 = game.player.hmPokemon;
                                        Objects.requireNonNull(pokemon6);
                                        pokemon5.standingAction = new Pokemon.Moving(game.player.hmPokemon.dirFacing, 1, 1.0f, true, true, null);
                                    }
                                    if (!game.player.currFieldMove.equals("")) {
                                        game.player.hmPokemon.standingAction.append(new CallMethod(game.player, "swapSprites", new Object[]{game.player.hmPokemon}, null));
                                    }
                                    game.player.hmPokemon.standingAction.append(new CallMethod(game.player.hmPokemon, "removeDrawActions", new Object[]{game}, new SetField(game.player, "hmPokemon", null, new SetField(game, "playerCanMove", true, null))));
                                    game.player.currFieldMove = "";
                                    game.insertAction(game.player.hmPokemon.standingAction);
                                    return;
                                }
                            }
                        } else {
                            bTimer++;
                        }
                    }
                    if (InputProcessor.aJustPressed) {
                        Vector2 pos = game.player.facingPos();
                        Tile currTile = game.map.tiles.get(pos);
                        if (currTile != null) {
                            System.out.println("facingTile.name");
                            System.out.println(currTile.name);
                            System.out.println("facingTile.nameUpper");
                            System.out.println(currTile.nameUpper);
                            System.out.println("facingTile.biome");
                            System.out.println(currTile.biome);
                            if (currTile.routeBelongsTo != null) {
                                System.out.println("facingTile.route");
                                System.out.println(currTile.routeBelongsTo.name);
                            }
                        }
                        if (game.player.currFieldMove.equals("BUILD")) {
                            boolean requirementsMet3 = true;
                            Iterator<String> it5 = game.player.buildTileRequirements.get(game.player.currBuildTile.name).keySet().iterator();
                            while (true) {
                                if (!it5.hasNext()) {
                                    break;
                                }
                                String reqName3 = it5.next();
                                if (game.player.hasItem(reqName3)) {
                                    if (game.player.getItemAmount(reqName3).intValue() < game.player.buildTileRequirements.get(game.player.currBuildTile.name).get(reqName3).intValue()) {
                                        requirementsMet3 = false;
                                        break;
                                    }
                                } else {
                                    requirementsMet3 = false;
                                    break;
                                }
                            }
                            if (game.player.currBuildTile.name.contains("house")) {
                                Tile upTile = game.map.interiorTiles.get(game.map.interiorTilesIndex).get(pos.cpy().add(0.0f, 16.0f));
                                requirementsMet3 = requirementsMet3 && (upTile == null || upTile.name.contains("house") || upTile.name.contains("rug"));
                            }
                            if (game.player.currBuildTile.name.contains("picture")) {
                                requirementsMet3 = requirementsMet3 && currTile != null && !currTile.nameUpper.contains("_left") && !currTile.nameUpper.contains("_right");
                            }
                            boolean isTorch = game.player.currBuildTile.name.contains("torch") || game.player.currBuildTile.name.equals("house_clock1") || game.player.currBuildTile.name.contains("picture") || game.player.currBuildTile.name.contains("window");
                            if (isTorch) {
                                requirementsMet3 = requirementsMet3 && currTile != null && !currTile.items().containsKey("torch") && currTile.isSolid && !currTile.isWater && !currTile.nameUpper.contains("roof");
                                String[] notAllowedTiles = {"regi", "tree", "bush", "table", "bed", "shelf", "plant", "couch", "kiln", "chest", "trashcan"};
                                for (String name : notAllowedTiles) {
                                    requirementsMet3 = requirementsMet3 && currTile != null && !currTile.name.contains(name) && !currTile.nameUpper.contains(name);
                                }
                            }
                            if (game.player.currBuildTile.name.contains("door")) {
                                requirementsMet3 &= !game.map.overworldTiles.get(pos.cpy().add(0.0f, -16.0f)).nameUpper.contains("roof");
                            }
                            if (game.player.currBuildTile.name.contains("window")) {
                                requirementsMet3 &= currTile.name.contains("house") || currTile.nameUpper.contains("house");
                            }
                            boolean isCarpet = game.player.currBuildTile.name.contains("carpet");
                            if (isCarpet) {
                                Tile exteriorTile = game.map.overworldTiles.get(pos);
                                requirementsMet3 = requirementsMet3 && exteriorTile != null && exteriorTile.nameUpper.contains("house") && (currTile == null || (!currTile.name.contains("rug") && !game.player.currBuildTile.name.equals(currTile.name) && (!game.player.currBuildTile.name.equals("house_carpet1") || !currTile.name.equals("house5_floor1"))));
                            }
                            boolean isBridge = game.player.currBuildTile.name.contains("bridge");
                            if (isBridge) {
                                requirementsMet3 = requirementsMet3 && currTile != null && (currTile.name.contains("water") || currTile.name.contains("_tidal") || currTile.name.contains("lava"));
                            }
                            if (game.player.currBuildTile.name.contains("stairs_up")) {
                                int currLevel = game.map.interiorTilesIndex - 100;
                                if (currLevel < 0) {
                                    game.playerCanMove = false;
                                    game.insertAction(new DisplayText(game, "Canì build stairs underground.", (String) null, (Action) null, new SetField(game, "playerCanMove", true, null)));
                                    return;
                                }
                                int buildingHeight = game.map.getBuildingHeight(game.map.overworldTiles.get(pos));
                                if (buildingHeight == -1) {
                                    game.playerCanMove = false;
                                    game.insertAction(new DisplayText(game, "This house needs a completed roof.", (String) null, (Action) null, new RunCode(() -> {
                                        game.playerCanMove = true;
                                    }, null)));
                                    return;
                                } else if (currLevel + 1 >= buildingHeight) {
                                    game.playerCanMove = false;
                                    game.insertAction(new DisplayText(game, "This house needs to be taller.", (String) null, (Action) null, new SetField(game, "playerCanMove", true, null)));
                                    return;
                                }
                            }
                            boolean isChimney = game.player.currBuildTile.name.contains("chimney");
                            if (isChimney) {
                                requirementsMet3 = requirementsMet3 && currTile != null && currTile.nameUpper.contains("roof");
                            }
                            if (game.player.currBuildTile.name.contains("bed") || game.player.currBuildTile.name.equals("house_couch2") || game.player.currBuildTile.name.equals("house_couch4")) {
                                Tile upTile2 = game.map.interiorTiles.get(game.map.interiorTilesIndex).get(pos.cpy().add(0.0f, 16.0f));
                                requirementsMet3 &= upTile2 != null && !upTile2.isSolid && !upTile2.nameUpper.contains("door");
                            } else if (game.player.currBuildTile.name.equals("house_couch1")) {
                                Tile rightTile = game.map.interiorTiles.get(game.map.interiorTilesIndex).get(pos.cpy().add(16.0f, 0.0f));
                                requirementsMet3 &= rightTile != null && !rightTile.isSolid && !rightTile.nameUpper.contains("door");
                            }
                            boolean requirementsMet4 = requirementsMet3 & (currTile == null || !currTile.nameUpper.contains("stairs_down")) & (currTile == null || !currTile.nameUpper.contains("gate"));
                            if (!isTorch) {
                                requirementsMet4 &= currTile == null || !currTile.isLedge;
                            }
                            boolean isSolid2 = currTile == null || currTile.isSolid;
                            boolean isDoor = currTile != null && currTile.nameUpper.contains("door");
                            boolean requirementsMet5 = requirementsMet4 & (currTile == null || !currTile.name.contains("rug"));
                            if ((isTorch || isCarpet || isBridge || isChimney || !isSolid2) && !isDoor && requirementsMet5) {
                                if (currTile == null) {
                                    currTile = new Tile(game.player.currBuildTile.name, pos.cpy(), true, (Route) null);
                                    game.map.tiles.put(pos.cpy(), currTile);
                                } else if (game.player.currBuildTile.name.contains("torch")) {
                                    currTile.items().put("torch", 1);
                                    currTile.isTorch = true;
                                } else if (isCarpet) {
                                    Tile[] tileArr = {game.map.tiles.get(currTile.position.cpy().add(0.0f, -16.0f)), currTile};
                                    for (Tile tile2 : tileArr) {
                                        if (tile2 != null && tile2.nameUpper.contains("bed")) {
                                            tile2.nameUpper = tile2.nameUpper.split("colored")[0] + "colored" + game.player.currBuildTile.name;
                                            tile2.init();
                                        }
                                    }
                                    currTile.name = game.player.currBuildTile.name;
                                    currTile.init();
                                } else if (isBridge) {
                                    currTile.squish(currTile.name);
                                    currTile.name = game.player.currBuildTile.name;
                                    currTile.belowBridge = false;
                                    currTile.init();
                                    Tile down = game.map.tiles.get(currTile.position.cpy().add(0.0f, -16.0f));
                                    if (down != null && (down.name.contains("water") || down.name.contains("lava"))) {
                                        down.belowBridge = true;
                                    }
                                } else if (currTile.nameUpper.contains("interiorwall") && !game.player.currBuildTile.name.contains("torch")) {
                                    currTile.nameUpper += "|" + game.player.currBuildTile.name;
                                    currTile.init();
                                } else if (game.player.currBuildTile.name.contains("exteriorwindows")) {
                                    currTile.nameUpper += "exteriorwindows";
                                    currTile.init();
                                } else if (isChimney) {
                                    currTile.nameUpper += "chimney";
                                    currTile.init();
                                } else {
                                    currTile.nameUpper = game.player.currBuildTile.name;
                                    currTile.init();
                                }
                                if (game.player.currBuildTile.name.contains("chest")) {
                                    if (currTile.routeBelongsTo == null) {
                                        currTile.routeBelongsTo = new Route("", 2);
                                    } else {
                                        currTile.routeBelongsTo = new Route(currTile.routeBelongsTo.name, currTile.routeBelongsTo.level);
                                    }
                                }
                                currTile.updateMiniMap(game);
                                game.map.adjustSurroundingTiles(currTile);
                                if (game.player.currBuildTile.name.contains("bed") || game.player.currBuildTile.name.equals("house_couch2") || game.player.currBuildTile.name.equals("house_couch4")) {
                                    Tile upTile3 = game.map.tiles.get(currTile.position.cpy().add(0.0f, 16.0f));
                                    upTile3.nameUpper = "onpress_above";
                                    upTile3.isSolid = true;
                                } else if (game.player.currBuildTile.name.equals("house_couch1")) {
                                    Tile right = game.map.tiles.get(currTile.position.cpy().add(16.0f, 0.0f));
                                    right.nameUpper = "onpress_left";
                                    right.isSolid = true;
                                } else if (game.player.currBuildTile.name.equals("stairs_up1")) {
                                    HashMap<Vector2, Tile> interiorTiles = game.map.getInteriorLayer(game.map.interiorTilesIndex + 1);
                                    for (int i = -1; i < 2; i++) {
                                        for (int j = -1; j < 2; j++) {
                                            String nameUpper = "";
                                            if (i == 0 && j == 0) {
                                                nameUpper = "stairs_down1";
                                            }
                                            Vector2 interiorPos = currTile.position.cpy().add((float) (i * 16), (float) (j * 16));
                                            Tile exteriorTile2 = game.map.overworldTiles.get(interiorPos);
                                            Tile interiorTile = interiorTiles.get(interiorPos);
                                            if (exteriorTile2 != null && exteriorTile2.nameUpper.contains("house") && (nameUpper.equals("stairs_down1") || interiorTile == null || interiorTile.name.contains("wall"))) {
                                                interiorTiles.put(interiorPos.cpy(), new Tile("house5_floor1", nameUpper, interiorPos.cpy()));
                                            }
                                        }
                                    }
                                }
                                game.player.updateBuildTiles(game);
                                game.playerCanMove = false;
                                int timer = 30;
                                String soundName = "strength1";
                                if (isCarpet) {
                                    timer = 10;
                                    soundName = "gate1";
                                }
                                game.insertAction(new PlayMusic(soundName, (Action) null));
                                game.insertAction(new WaitFrames(game, timer, new SetField(game, "playerCanMove", true, null)));
                                for (String name2 : game.player.buildTileRequirements.get(game.player.currBuildTile.name).keySet()) {
                                    int value = game.player.buildTileRequirements.get(game.player.currBuildTile.name).get(name2).intValue();
                                    int newValue = game.player.getItemAmount(name2).intValue() - value;
                                    game.player.setItemAmount(name2, newValue);
                                    if (newValue <= 0) {
                                        game.player.removeItem(name2);
                                    }
                                    if (currTile.items().containsKey(name2)) {
                                        value += currTile.items().get(name2).intValue();
                                    }
                                    currTile.items().put(name2, Integer.valueOf(value));
                                }
                                DrawBuildRequirements.currBuilding = "";
                            }
                        } else if (currTile != null) {
                            if (game.player.currPlanting != null) {
                                if (game.player.currPlanting.equals("manure")) {
                                    if (!currTile.nameUpper.contains("fertilized") && (currTile.nameUpper.contains("tree_planted") || currTile.nameUpper.contains("bush2_color"))) {
                                        currTile.nameUpper += "_fertilized";
                                        game.map.tiles.put(currTile.position, new Tile("mountain1", currTile.nameUpper, currTile.position.cpy(), true, currTile.routeBelongsTo));
                                        game.insertAction(new PlayMusic("seed1", (Action) null));
                                    }
                                } else if (game.player.currPlanting.equals("miracle seed")) {
                                    if (currTile.nameUpper.equals("") && (currTile.name.equals("green1") || currTile.name.contains("snow") || currTile.name.contains("sand") || currTile.name.contains("desert") || currTile.name.contains("green_savanna") || currTile.name.equals("green9") || currTile.name.equals("green10") || currTile.name.equals("green11") || currTile.name.equals("green12") || currTile.name.contains("flower"))) {
                                        game.map.tiles.put(currTile.position, new Tile(currTile.name, "grass_planted", currTile.position.cpy(), true, currTile.routeBelongsTo));
                                        game.insertAction(new PlayMusic("seed1", (Action) null));
                                    }
                                } else if (game.player.currPlanting.equals("berry seed")) {
                                    if (currTile.nameUpper.equals("") && (currTile.name.equals("green1") || currTile.name.contains("snow") || currTile.name.contains("sand") || currTile.name.contains("desert") || currTile.name.equals("green9") || currTile.name.equals("green10") || currTile.name.equals("green11") || currTile.name.equals("green12") || currTile.name.contains("volcano") || currTile.name.contains("savanna") || currTile.name.contains("graveyard") || currTile.name.contains("flower"))) {
                                        game.playerCanMove = false;
                                        game.insertAction(new WaitFrames(game, 10, new SplitAction(new PlantTree("berry_planted", pos, null), new PlayMusic("seed1", new SetField(game, "playerCanMove", true, new WaitFrames(game, 4, new PlayMusic("ledge2", (Action) null)))))));
                                    }
                                } else if (game.player.currPlanting.contains("apricorn")) {
                                    if ((currTile.name.equals("green1") || currTile.name.contains("flower") || currTile.name.contains("sand") || currTile.name.contains("snow") || currTile.name.contains("desert")) && !currTile.nameUpper.contains("tree") && !currTile.isSolid) {
                                        game.playerCanMove = false;
                                        game.insertAction(new WaitFrames(game, 10, new SplitAction(new PlantTree(pos, null), new PlayMusic("seed1", new SetField(game, "playerCanMove", true, new WaitFrames(game, 4, new PlayMusic("ledge2", (Action) null)))))));
                                    } else {
                                        return;
                                    }
                                }
                                game.player.setItemAmount(game.player.currPlanting, game.player.getItemAmount(game.player.currPlanting).intValue() - 1);
                                if (game.player.getItemAmount(game.player.currPlanting).intValue() <= 0) {
                                    game.player.removeItem(game.player.currPlanting);
                                    game.player.currPlanting = null;
                                    return;
                                }
                                return;
                            } else if (game.player.currFieldMove.equals("DIG")) {
                                if (currTile.hasItem != null) {
                                    currTile.onPressA(game);
                                    return;
                                } else if (!game.player.currBuildTile.name.contains("hole")) {
                                    boolean requirementsMet6 = true;
                                    Iterator<String> it6 = game.player.buildTileRequirements.get(game.player.currBuildTile.name).keySet().iterator();
                                    while (true) {
                                        if (!it6.hasNext()) {
                                            break;
                                        }
                                        String reqName4 = it6.next();
                                        if (game.player.hasItem(reqName4)) {
                                            if (game.player.getItemAmount(reqName4).intValue() < game.player.buildTileRequirements.get(game.player.currBuildTile.name).get(reqName4).intValue()) {
                                                requirementsMet6 = false;
                                                break;
                                            }
                                        } else {
                                            requirementsMet6 = false;
                                            break;
                                        }
                                    }
                                    if (requirementsMet6) {
                                        if (game.player.currBuildTile.name.equals("ledges3_none")) {
                                            String name3 = "ledges3_none";
                                            if (currTile.name.contains("snow") || currTile.name.contains("ice")) {
                                                name3 = "ledges3snow_none";
                                            } else if (currTile.name.contains("volcano") || currTile.name.contains("soot")) {
                                                name3 = "ledges3volcano_none";
                                            }
                                            currTile.nameUpper = name3;
                                            currTile.init();
                                            currTile.updateMiniMap(game);
                                            game.map.ledgify(currTile);
                                        } else if (game.player.currBuildTile.name.equals("green_woodedlake") || game.player.currBuildTile.name.equals("green_deepforest")) {
                                            currTile.name = "green1";
                                            currTile.nameUpper = "";
                                            currTile.routeBelongsTo = game.player.currBuildTile.routeBelongsTo;
                                            if (game.player.currBuildTile.name.equals("green_woodedlake")) {
                                                currTile.biome = "wooded_lake";
                                            } else if (game.player.currBuildTile.name.equals("green_deepforest")) {
                                                currTile.biome = "deep_forest";
                                            }
                                            currTile.init();
                                            currTile.updateMiniMap(game);
                                            game.map.adjustSurroundingTiles(currTile);
                                        } else {
                                            currTile.name = game.player.currBuildTile.name;
                                            currTile.nameUpper = "";
                                            currTile.guessBiomeType();
                                            currTile.init();
                                            currTile.guessBiomeType();
                                            currTile.updateMiniMap(game);
                                            game.map.adjustSurroundingTiles(currTile);
                                        }
                                        for (String name4 : game.player.buildTileRequirements.get(game.player.currBuildTile.name).keySet()) {
                                            int newValue2 = game.player.getItemAmount(name4).intValue() - game.player.buildTileRequirements.get(game.player.currBuildTile.name).get(name4).intValue();
                                            game.player.setItemAmount(name4, newValue2);
                                            if (newValue2 <= 0) {
                                                game.player.removeItem(name4);
                                            }
                                        }
                                        game.playerCanMove = false;
                                        game.player.currFieldMove = "";
                                        game.player.currSprite = game.player.altMovingSprites.get(game.player.dirFacing);
                                        game.insertAction(new WaitFrames(game, 16, new SetField(game.player, "currFieldMove", "DIG", new SetField(game, "playerCanMove", true, null))));
                                        game.insertAction(new WaitFrames(game, 10, new SetField(game.player, "currSprite", game.player.standingSprites.get(game.player.dirFacing), null)));
                                        game.insertAction(new PlayMusic("ap1", 1.0f, true, null));
                                        return;
                                    }
                                    return;
                                } else {
                                    boolean requirementsMet7 = currTile.nameUpper.equals("") || currTile.nameUpper.contains("_cracked") || currTile.nameUpper.contains("ledges3");
                                    if (!currTile.nameUpper.contains("ledges3")) {
                                        requirementsMet7 &= !currTile.isSolid && !currTile.name.contains("door") && !currTile.name.contains("bridge") && !currTile.name.contains("rug");
                                    }
                                    if (currTile.routeBelongsTo != null) {
                                        requirementsMet7 &= !currTile.routeBelongsTo.isDungeon;
                                    }
                                    if (requirementsMet7) {
                                        String gotTerrain = "grass";
                                        if (currTile.nameUpper.contains("ledges3")) {
                                            gotTerrain = "hard stone";
                                        } else if (currTile.name.contains("sand") || currTile.name.equals("stalagmite1")) {
                                            gotTerrain = "soft sand";
                                        } else if (currTile.name.contains("snow") || currTile.name.contains("ice")) {
                                            gotTerrain = "nevermeltice";
                                        } else if (currTile.name.contains("mountain")) {
                                            gotTerrain = "light clay";
                                        } else if (currTile.name.contains("desert")) {
                                            gotTerrain = "dry sand";
                                        } else if (currTile.name.contains("flower")) {
                                            gotTerrain = "flowers";
                                        } else if (currTile.name.contains("volcano") || currTile.name.contains("soot")) {
                                            gotTerrain = "ashen soil";
                                        } else if (currTile.name.equals("green9") || currTile.name.contains("green10") || currTile.name.contains("green11") || currTile.name.contains("green12")) {
                                            gotTerrain = "cursed soil";
                                        } else if (currTile.name.contains("ledges3")) {
                                            gotTerrain = "hard stone";
                                        } else if (currTile.name.contains("green_savanna")) {
                                            gotTerrain = "dry soil";
                                        } else if (currTile.routeBelongsTo != null && currTile.routeBelongsTo.name.equals("wooded_lake1")) {
                                            gotTerrain = "damp soil";
                                        } else if (currTile.routeBelongsTo != null && currTile.routeBelongsTo.name.equals("deep_forest")) {
                                            gotTerrain = "mystic soil";
                                        }
                                        if (currTile.nameUpper.equals("desert4_cracked")) {
                                            String[] fossilTypes = {"old amber", "dome fossil", "helix fossil", "claw fossil", "root fossil", "shield fossil", "skull fossil", "sun stone", "fire stone"};
                                            currTile.hasItem = fossilTypes[Game.rand.nextInt(fossilTypes.length)];
                                            currTile.hasItemAmount = 1;
                                        } else if (currTile.nameUpper.equals("forest_cracked")) {
                                            String[] fossilTypes2 = {"leaf stone"};
                                            currTile.hasItem = fossilTypes2[Game.rand.nextInt(fossilTypes2.length)];
                                            currTile.hasItemAmount = 1;
                                        } else if (currTile.nameUpper.equals("deepforest_cracked")) {
                                            String[] fossilTypes3 = {"dawn stone", "shiny stone"};
                                            currTile.hasItem = fossilTypes3[Game.rand.nextInt(fossilTypes3.length)];
                                            currTile.hasItemAmount = 1;
                                        } else if (currTile.nameUpper.equals("graveyard_cracked")) {
                                            String[] fossilTypes4 = {"dusk stone"};
                                            currTile.hasItem = fossilTypes4[Game.rand.nextInt(fossilTypes4.length)];
                                            currTile.hasItemAmount = 1;
                                        } else if (currTile.nameUpper.equals("snow_cracked")) {
                                            String[] fossilTypes5 = {"ice stone"};
                                            currTile.hasItem = fossilTypes5[Game.rand.nextInt(fossilTypes5.length)];
                                            currTile.hasItemAmount = 1;
                                        } else if (currTile.nameUpper.equals("volcano_cracked")) {
                                            String[] fossilTypes6 = {"fire stone"};
                                            currTile.hasItem = fossilTypes6[Game.rand.nextInt(fossilTypes6.length)];
                                            currTile.hasItemAmount = 1;
                                        } else if (currTile.nameUpper.equals("beach_cracked")) {
                                            String[] fossilTypes7 = {"water stone"};
                                            currTile.hasItem = fossilTypes7[Game.rand.nextInt(fossilTypes7.length)];
                                            currTile.hasItemAmount = 1;
                                        } else if (currTile.nameUpper.equals("mountain3_cracked")) {
                                            String[] fossilTypes8 = {"thunderstone"};
                                            currTile.hasItem = fossilTypes8[Game.rand.nextInt(fossilTypes8.length)];
                                            currTile.hasItemAmount = 1;
                                        } else if (currTile.nameUpper.equals("tidal1_cracked")) {
                                            String[] fossilTypes9 = {"clear glass", "water stone", "revive", "ultra ball", "big pearl", "star piece"};
                                            currTile.hasItem = fossilTypes9[Game.rand.nextInt(fossilTypes9.length)];
                                            currTile.hasItemAmount = 1;
                                        }
                                        currTile.nameUpper = game.player.currDigTile.name;
                                        currTile.init();
                                        currTile.updateMiniMap(game);
                                        game.map.adjustSurroundingTiles(currTile);
                                        game.insertAction(new PlayMusic("dig1", 1.0f, true, null));
                                        game.insertAction(new OverworldAnimation(game, "dig_overworld_gsc", currTile.position.cpy().add(-104.0f, -52.0f), true, null));
                                        game.insertAction(new OverworldAnimation(game, "dig_overworld_gsc", currTile.position.cpy().add(-40.0f, -52.0f), false, null));
                                        game.playerCanMove = false;
                                        game.player.currFieldMove = "";
                                        game.player.currSprite = game.player.altMovingSprites.get(game.player.dirFacing);
                                        game.insertAction(new WaitFrames(game, 8, new WaitFrames(game, 8, new SetField(game.player, "currFieldMove", "DIG", new SetField(game, "playerCanMove", true, null)))));
                                        game.insertAction(new WaitFrames(game, 10, new SetField(game.player, "currSprite", game.player.standingSprites.get(game.player.dirFacing), null)));
                                        HashMap<String, Integer> items = new HashMap<>();
                                        items.put(gotTerrain, 1);
                                        game.insertAction(new DrawItemPickup(items, null));
                                        if (game.player.hasItem(gotTerrain)) {
                                            game.player.setItemAmount(gotTerrain, game.player.getItemAmount(gotTerrain).intValue() + 1);
                                            return;
                                        } else {
                                            game.player.setItemAmount(gotTerrain, 1);
                                            return;
                                        }
                                    } else {
                                        currTile.onPressA(game);
                                        return;
                                    }
                                }
                            } else if (game.player.currFieldMove.equals("HEADBUTT")) {
                                if (currTile.isHeadbuttable) {
                                    Action nextAction = new SetField(game, "playerCanMove", true, null);
                                    if (currTile.routeBelongsTo != null && !currTile.routeBelongsTo.storedPokemon.isEmpty()) {
                                        game.playerCanMove = false;
                                        game.battle.oppPokemon = currTile.routeBelongsTo.storedPokemon.get(0);
                                        game.player.setCurrPokemon();
                                        game.map.currRoute = currTile.routeBelongsTo;
                                        nextAction = new WaitFrames(game, 16, new SetField(game.musicController, "startBattle", "wild", Battle.getIntroAction(game)));
                                        this.checkWildEncounter = false;
                                        shouldMove = false;
                                    }
                                    game.insertAction(new HeadbuttTreeAnim(game, game.map.tiles.get(pos), nextAction));
                                    game.playerCanMove = false;
                                }
                            } else if (game.player.currFieldMove.equals("CUT")) {
                                if (currTile.nameUpper.equals("solid")) {
                                    Vector2[] positions = {pos.cpy().add(-16.0f, 0.0f), pos.cpy().add(-16.0f, -16.0f), pos.cpy().add(0.0f, -16.0f)};
                                    int length = positions.length;
                                    int i2 = 0;
                                    while (true) {
                                        if (i2 >= length) {
                                            break;
                                        }
                                        Vector2 position = positions[i2];
                                        if (game.map.tiles.get(position).nameUpper.equals("aloe_large1")) {
                                            pos = position;
                                            currTile = game.map.tiles.get(pos);
                                            break;
                                        }
                                        i2++;
                                    }
                                }
                                if (currTile.isCuttable) {
                                    for (int interiorIndex = 100; interiorIndex < game.map.interiorTiles.size(); interiorIndex++) {
                                        Tile interiorTile2 = game.map.interiorTiles.get(interiorIndex).get(pos);
                                        if (interiorTile2 != null && interiorTile2.nameUpper.contains("chest1") && interiorTile2.routeBelongsTo != null && !interiorTile2.routeBelongsTo.storedPokemon.isEmpty()) {
                                            game.playerCanMove = false;
                                            game.insertAction(new DisplayText(game, "A box indoors must be emptied before this can be CUT.", (String) null, (Action) null, new SetField(game, "playerCanMove", true, null)));
                                            return;
                                        }
                                    }
                                    if (!currTile.nameUpper.contains("chest1") || currTile.routeBelongsTo == null || currTile.routeBelongsTo.storedPokemon.isEmpty()) {
                                        if (currTile.name.contains("tree_large1") || currTile.nameUpper.equals("tree_savanna1")) {
                                            if (game.player.hmPokemon == null || game.player.hmPokemon.hasEvo()) {
                                                game.playerCanMove = false;
                                                game.insertAction(new DisplayText(game, game.player.hmPokemon.nickname.toUpperCase(Locale.ROOT) + " must be fully evolved to CUT large trees.", (String) null, (Action) null, new SetField(game, "playerCanMove", true, null)));
                                                return;
                                            } else if (currTile.name.contains("tree_large1") && !currTile.name.equals("tree_large1")) {
                                                Vector2[] positions2 = {pos.cpy().add(-16.0f, 0.0f), pos.cpy().add(-16.0f, -16.0f), pos.cpy().add(0.0f, -16.0f)};
                                                int length2 = positions2.length;
                                                int i3 = 0;
                                                while (true) {
                                                    if (i3 >= length2) {
                                                        break;
                                                    }
                                                    Vector2 position2 = positions2[i3];
                                                    if (game.map.tiles.get(position2).name.equals("tree_large1")) {
                                                        pos = position2;
                                                        break;
                                                    }
                                                    i3++;
                                                }
                                            }
                                        }
                                        Action action2 = new CutTreeAnim(game, game.map.tiles.get(pos), null);
                                        Tile upTile4 = game.map.tiles.get(pos.cpy().add(0.0f, 16.0f));
                                        if (upTile4 != null && upTile4.name.contains("rug") && currTile.nameUpper.contains("roof")) {
                                            game.map.tiles.put(upTile4.position.cpy(), new Tile("green1", upTile4.position.cpy(), true, upTile4.routeBelongsTo));
                                        }
                                        Tile left = game.map.tiles.get(pos.cpy().add(-16.0f, 0.0f));
                                        if (left != null && left.name.contains("rug") && (currTile.nameUpper.contains("E") || currTile.nameUpper.contains("left"))) {
                                            game.map.tiles.put(left.position.cpy(), new Tile("green1", left.position.cpy(), true, left.routeBelongsTo));
                                        }
                                        Tile right2 = game.map.tiles.get(pos.cpy().add(16.0f, 0.0f));
                                        if (right2 != null && right2.name.contains("rug") && (currTile.nameUpper.contains("W") || currTile.nameUpper.contains("right"))) {
                                            game.map.tiles.put(right2.position.cpy(), new Tile("green1", right2.position.cpy(), true, right2.routeBelongsTo));
                                        }
                                        if (upTile4 != null && (currTile.nameUpper.contains("bed") || currTile.nameUpper.equals("house_couch2") || currTile.nameUpper.equals("house_couch4"))) {
                                            upTile4.nameUpper = "";
                                            upTile4.isSolid = false;
                                        }
                                        if (right2 != null && currTile.nameUpper.equals("house_couch1")) {
                                            right2.nameUpper = "";
                                            right2.isSolid = false;
                                        }
                                        if (currTile.nameUpper.contains("stairs_up") && (aboveTile = game.map.getInteriorLayer(game.map.interiorTilesIndex + 1).get(pos)) != null && aboveTile.nameUpper.contains("stairs_down")) {
                                            aboveTile.nameUpper = "";
                                            aboveTile.overSprite = null;
                                            aboveTile.init();
                                        }
                                        if (game.map.tiles == game.map.overworldTiles) {
                                            for (int interiorIndex2 = 100; interiorIndex2 < game.map.interiorTiles.size(); interiorIndex2++) {
                                                HashMap<Vector2, Tile> interiorTiles2 = game.map.interiorTiles.get(interiorIndex2);
                                                Tile interiorTile3 = interiorTiles2.remove(pos);
                                                if (interiorTile3 != null) {
                                                    Tile upTile5 = interiorTiles2.get(interiorTile3.position.cpy().add(0.0f, 16.0f));
                                                    if (upTile5 != null && (upTile5.name.contains("wall") || upTile5.name.contains("door"))) {
                                                        interiorTiles2.remove(upTile5.position);
                                                    }
                                                    if (upTile5 != null && (currTile.nameUpper.contains("bed") || currTile.nameUpper.equals("house_couch2") || currTile.nameUpper.equals("house_couch4"))) {
                                                        upTile5.nameUpper = "";
                                                        upTile5.isSolid = false;
                                                    }
                                                    Tile right3 = interiorTiles2.get(interiorTile3.position.cpy().add(16.0f, 0.0f));
                                                    if (right3 != null && currTile.nameUpper.equals("house_couch1")) {
                                                        right3.nameUpper = "";
                                                        right3.isSolid = false;
                                                    }
                                                    for (String name5 : interiorTile3.items().keySet()) {
                                                        int value2 = interiorTile3.items().get(name5).intValue();
                                                        if (currTile.items().containsKey(name5)) {
                                                            value2 += currTile.items().get(name5).intValue();
                                                        }
                                                        currTile.items().put(name5, Integer.valueOf(value2));
                                                    }
                                                }
                                            }
                                        }
                                        game.playerCanMove = false;
                                        if (!currTile.items().isEmpty()) {
                                            currTile.items().remove("torch");
                                            action2.append(new SplitAction(new DrawItemPickup(currTile.items(), null), null));
                                            for (String item : currTile.items().keySet()) {
                                                System.out.println(item);
                                                if (game.player.hasItem(item)) {
                                                    game.player.setItemAmount(item, game.player.getItemAmount(item).intValue() + currTile.items().get(item).intValue());
                                                } else {
                                                    game.player.setItemAmount(item, currTile.items().get(item).intValue());
                                                }
                                            }
                                            currTile.items().clear();
                                        }
                                        action2.append(new SetField(game, "playerCanMove", true, null));
                                        game.insertAction(action2);
                                        if (game.type == Game.Type.CLIENT) {
                                            game.client.sendTCP(new Network.UseHM(game.player.network.id, 0, "CUT", game.player.dirFacing));
                                        }
                                    } else {
                                        game.playerCanMove = false;
                                        game.insertAction(new DisplayText(game, "The box must be emptied before it can be CUT.", (String) null, (Action) null, new SetField(game, "playerCanMove", true, null)));
                                        return;
                                    }
                                }
                            } else if (!game.player.currFieldMove.equals("SMASH")) {
                                currTile.onPressA(game);
                            } else if (currTile.isSmashable) {
                                Action action3 = new CutTreeAnim(game, game.map.tiles.get(pos), null);
                                game.playerCanMove = false;
                                currTile.items().remove("torch");
                                if (!currTile.items().isEmpty()) {
                                    action3.append(new SplitAction(new DrawItemPickup(currTile.items(), null), null));
                                    for (String item2 : currTile.items().keySet()) {
                                        if (game.player.hasItem(item2)) {
                                            game.player.setItemAmount(item2, game.player.getItemAmount(item2).intValue() + currTile.items().get(item2).intValue());
                                        } else {
                                            game.player.setItemAmount(item2, currTile.items().get(item2).intValue());
                                        }
                                    }
                                    currTile.items().clear();
                                }
                                if (currTile.routeBelongsTo != null && !currTile.routeBelongsTo.storedPokemon.isEmpty()) {
                                    game.player.setCurrPokemon();
                                    game.playerCanMove = false;
                                    game.battle.oppPokemon = currTile.routeBelongsTo.storedPokemon.get(0);
                                    action3.append(new WaitFrames(game, 16, new SetField(game.musicController, "startBattle", "wild", Battle.getIntroAction(game))));
                                    this.checkWildEncounter = false;
                                    shouldMove = false;
                                } else if (currTile.nameUpper.contains("gravestone") && Game.rand.nextInt(9) == 0) {
                                    game.player.setCurrPokemon();
                                    game.playerCanMove = false;
                                    String[] pokemon7 = {"cubone", "marowak", "whismur", "machop", "machoke", "phanpy", "makuhita", "houndour", "growlithe", "oddish", "pidgey", "hoppip", "taillow", "bulbasaur", "charmander", "chikorita", "pikachu", "mankey", "ponyta", "cyndaquil", "eevee", "rattata", "sentret", "mareep", "squirtle", "totodile", "marill", "sandshrew", "sandslash", "swinub"};
                                    game.battle.oppPokemon = new Pokemon(pokemon7[Game.rand.nextInt(pokemon7.length)], 22);
                                    game.battle.oppPokemon.spookify();
                                    CallMethod callMethod = new CallMethod(game.currMusic, "pause", new Object[0], new PlayMusic("ledge2", (Action) null));
                                    Player player3 = game.player;
                                    Objects.requireNonNull(player3);
                                    action3.append(new SplitAction(callMethod, new Player.Emote("!", new DisplayText(game, "You feel a presence around you...", (String) null, (Action) null, new WaitFrames(game, 16, new SetField(game.musicController, "startBattle", "wild", Battle.getIntroAction(game)))))));
                                }
                                action3.append(new SetField(game, "playerCanMove", true, null));
                                game.insertAction(action3);
                            }
                        }
                    }
                    if (this.isRunning) {
                        game.player.currSprite = new Sprite(game.player.standingSprites.get(game.player.dirFacing + "_running"));
                    } else {
                        game.player.currSprite = new Sprite(game.player.standingSprites.get(game.player.dirFacing));
                    }
                    if (shouldMove) {
                        game.actionStack.remove(this);
                        if (game.type == Game.Type.CLIENT) {
                            game.client.sendTCP(new Network.MovePlayer(game.player.network.id, game.player.dirFacing, InputProcessor.bPressed));
                        }
                        Tile facingTile = game.map.tiles.get(newPos);
                        String oppDir = Player.oppDirs.get(game.player.dirFacing);
                        if (this.currTile.name.equals("rug2_right") || this.currTile.name.equals("rug2_left")) {
                            if (!game.player.dirFacing.equals("left") || !this.currTile.name.equals("rug2_left")) {
                                if (game.player.dirFacing.equals("right") && this.currTile.name.equals("rug2_right")) {
                                    if (game.map.tiles == game.map.overworldTiles) {
                                        game.insertAction(new EnterBuilding(game, "enter", game.map.interiorTiles.get(game.map.interiorTilesIndex), new PlayerMoving(game, this.alternate)));
                                        return;
                                    } else {
                                        game.insertAction(new EnterBuilding(game, "exit", game.map.overworldTiles, new PlayerMoving(game, this.alternate)));
                                        return;
                                    }
                                }
                            } else if (game.map.tiles == game.map.overworldTiles) {
                                game.insertAction(new EnterBuilding(game, "enter", game.map.interiorTiles.get(game.map.interiorTilesIndex), new PlayerMoving(game, this.alternate)));
                                return;
                            } else {
                                game.insertAction(new EnterBuilding(game, "exit", game.map.overworldTiles, new PlayerMoving(game, this.alternate)));
                                return;
                            }
                        } else if ((this.currTile.name.contains("rug") && (facingTile == null || facingTile.name.contains("wall"))) || ((facingTile != null && facingTile.name.contains("entrance")) || (game.map.tiles == game.map.overworldTiles && game.player.dirFacing.equals("down") && this.currTile.name.contains("rug")))) {
                            if (game.map.tiles == game.map.overworldTiles) {
                                game.insertAction(new EnterBuilding(game, "enter", game.map.interiorTiles.get(game.map.interiorTilesIndex), new PlayerMoving(game, this.alternate)));
                                return;
                            } else {
                                game.insertAction(new EnterBuilding(game, "exit", game.map.overworldTiles, new PlayerMoving(game, this.alternate)));
                                return;
                            }
                        }
                        if (facingTile == null) {
                            game.insertAction(new PlayerBump(game));
                        } else if (!Gdx.input.isKeyPressed(62) || !game.debugInputEnabled) {
                            if (!game.map.pokemon.containsKey(newPos) || game.map.pokemon.get(newPos).mapTiles != game.map.tiles) {
                                if (game.player.currFieldMove.equals("RIDE")) {
                                    if (facingTile.ledgeDir == null || (facingTile.ledgeDir.equals("up") && !game.player.dirFacing.equals("down"))) {
                                        if (!facingTile.isSolid && this.currTile != null && this.currTile.ledgeDir != null && !this.currTile.ledgeDir.equals("up") && (this.currTile.ledgeDir.equals(game.player.dirFacing) || this.currTile.ledgeDir.equals(oppDir))) {
                                            game.insertAction(new PlayerLedgeJumpFast(game));
                                            return;
                                        }
                                    } else if (facingTile.ledgeDir.equals(game.player.dirFacing) || facingTile.ledgeDir.equals(oppDir)) {
                                        if (facingTile.nameUpper.contains("fence")) {
                                            Tile fartherOutTile2 = game.map.tiles.get(newPos.cpy().add(newPos.cpy().sub(game.player.position)));
                                            if (fartherOutTile2 == null || fartherOutTile2.isSolid) {
                                                game.insertAction(new PlayerBump(game));
                                                return;
                                            } else {
                                                game.insertAction(new PlayerLedgeJump(game));
                                                return;
                                            }
                                        } else {
                                            game.insertAction(new PlayerLedgeJumpFast(game));
                                            return;
                                        }
                                    } else if (!facingTile.isLedge || this.currTile == null || !this.currTile.isLedge || !this.currTile.nameUpper.contains("inner")) {
                                        game.insertAction(new PlayerBump(game));
                                        return;
                                    } else {
                                        game.insertAction(new PlayerLedgeJumpFast(game));
                                        return;
                                    }
                                }
                                if (game.player.currFieldMove.equals("SURF")) {
                                    if (facingTile.isSolid && !facingTile.isWater) {
                                        game.insertAction(new PlayerBump(game));
                                    } else if (!facingTile.isWater) {
                                        game.player.swapSprites(game.player.hmPokemon);
                                        game.player.currFieldMove = "";
                                        game.player.acceptInput = false;
                                        game.player.hmPokemon.mapTiles = game.map.tiles;
                                        game.player.hmPokemon.dirFacing = game.player.dirFacing;
                                        game.player.hmPokemon.inWater = true;
                                        game.player.hmPokemon.position = game.player.position.cpy();
                                        game.player.hmPokemon.currOwSprite = game.player.hmPokemon.standingSprites.get(game.player.hmPokemon.dirFacing);
                                        Pokemon pokemon8 = game.player.hmPokemon;
                                        Objects.requireNonNull(pokemon8);
                                        Pokemon.DrawUpper drawUpper = new Pokemon.DrawUpper(true);
                                        drawUpper.layer = Action.Layer.map_131;
                                        drawUpper.firstStep(game);
                                        drawUpper.firstStep = false;
                                        game.insertAction(drawUpper);
                                        game.insertAction(new PlayerLedgeJumpFast(game, game.player, new SetField(game.player, "dirFacing", oppDir, new SetField(game.player, "currSprite", game.player.standingSprites.get(oppDir), new WaitFrames(game, 24, new CallMethod(game.player.hmPokemon, "removeDrawActions", new Object[]{game}, new PlayMusic("seed1", new SetField(game.player, "acceptInput", true, new PlayerStanding(game)))))))));
                                        game.player.hmPokemon = null;
                                    } else if (!game.map.boundingBox().contains(newPos)) {
                                        int something = 100;
                                        int randNum = Game.rand.nextInt(4) + 2;
                                        if (randNum > 4) {
                                            something = 80;
                                        } else if (randNum > 3) {
                                            something = 90;
                                        }
                                        int size = 100 * something * (randNum + 2);
                                        if (newPos.y > game.map.boundingBox().y + game.map.boundingBox().height) {
                                            awayDir = "down";
                                        } else if (newPos.y < game.map.boundingBox().y) {
                                            awayDir = "up";
                                        } else if (newPos.x < game.map.boundingBox().x) {
                                            awayDir = "right";
                                        } else {
                                            awayDir = "left";
                                        }
                                        game.insertAction(new PlayerMoving(game, this.player, this.alternate, new RunCode(() -> {
                                            game.playerCanMove = false;
                                        }, new DisplayText(game, "Going further will take you to a new area... keep going?", (String) null, true, false, (Action) new DrawYesNoMenu(null, new DisplayText.Clear(game, new WaitFrames(game, 3, new FadeMusic(game.currMusic, -0.0125f, game.currMusic.getVolume(), true, new GenerateWorld(size, this.player.dirFacing, new RunCode(() -> {
                                            game.playerCanMove = true;
                                        }, new PlayerMoving(game, this.alternate)))))), new DisplayText.Clear(game, new WaitFrames(game, 3, new RunCode(() -> {
                                            game.playerCanMove = true;
                                            game.player.dirFacing = awayDir;
                                        }, new PlayerMoving(game, this.alternate)))))))));
                                    } else {
                                        game.insertAction(new PlayerMoving(game, this.alternate));
                                    }
                                } else if (facingTile.isSolid) {
                                    game.insertAction(new PlayerBump(game));
                                } else if (this.currTile != null && this.currTile.ledgeDir != null && this.currTile.ledgeDir.equals("up") && game.player.dirFacing.equals("up")) {
                                    game.insertAction(new PlayerLedgeJumpFast(game));
                                } else if (facingTile.ledgeDir != null && facingTile.ledgeDir.equals("up") && game.player.dirFacing.equals("down")) {
                                    game.insertAction(new PlayerBump(game));
                                } else if (facingTile.ledgeDir != null && !facingTile.ledgeDir.equals("up")) {
                                    Tile fartherOutTile3 = game.map.tiles.get(newPos.cpy().add(newPos.cpy().sub(game.player.position)));
                                    if (!facingTile.ledgeDir.equals(game.player.dirFacing) || (fartherOutTile3 != null && (fartherOutTile3.isSolid || fartherOutTile3.ledgeDir != null))) {
                                        game.insertAction(new PlayerBump(game));
                                    } else {
                                        game.insertAction(new PlayerLedgeJump(game));
                                    }
                                } else if (!InputProcessor.bPressed || facingTile.name.contains("desert2") || facingTile.name.contains("soot1") || facingTile.name.contains("snow3") || facingTile.isTidal) {
                                    game.insertAction(new PlayerMoving(game, this.alternate));
                                } else {
                                    game.insertAction(new PlayerRunning(game, this.alternate));
                                }
                            } else {
                                game.insertAction(new PlayerBump(game));
                            }
                        } else if (InputProcessor.bPressed) {
                            game.insertAction(new PlayerRunning(game, this.alternate));
                        } else {
                            game.insertAction(new PlayerMoving(game, this.alternate));
                        }
                    } else {
                        this.alternate = false;
                        this.isRunning = false;
                    }
                } else if (InputProcessor.bJustPressed) {
                    if (game.type == Game.Type.CLIENT) {
                        game.client.sendTCP(new Network.Sleep(game.player.network.id, false));
                    }
                    game.player.isSleeping = false;
                    if (game.player.sleepingDir == null) {
                        game.player.dirFacing = "left";
                        game.insertAction(new WaitFrames(game, 24, new SetField(game.player, "dirFacing", "right", new PlayerMoving(game, game.player, false, new SetField(game.player, "dirFacing", "left", new SetField(game.player, "currSprite", game.player.standingSprites.get("left"), new WaitFrames(game, 24, new SetField(game.player, "drawSleepingBag", false, new WaitFrames(game, 24, new PlayerMoving(game, game.player, true, new SetField(game.player, "acceptInput", true, new SetField(game.player, "currSprite", game.player.standingSprites.get("down"), null))))))))))));
                        return;
                    }
                    game.player.sleepingDir = null;
                }
            }
        }
    }

    public void remoteStep(Game game) {
        Pokemon pokemon;
        if (this.player.canMove) {
            Vector2 newPos = new Vector2();
            if (game.type == Game.Type.SERVER) {
                if (this.player.network.syncTimer > 0) {
                    this.player.network.syncTimer++;
                }
                if (this.player.network.syncTimer > 240) {
                    this.player.network.syncTimer = 0;
                }
                if (!this.player.network.loadingZone.inner.contains(this.player.position)) {
                    LoadingZone oldZone = new LoadingZone(this.player.network.loadingZone);
                    oldZone.inner = new LoadingZone(this.player.network.loadingZone.inner);
                    if (this.player.position.x < oldZone.inner.x) {
                        this.player.network.loadingZone.translate(-112.0f, 0.0f);
                    } else if (this.player.position.x >= oldZone.inner.topRight().x) {
                        this.player.network.loadingZone.translate(112.0f, 0.0f);
                    }
                    if (this.player.position.y < oldZone.inner.y) {
                        this.player.network.loadingZone.translate(0.0f, -112.0f);
                    } else if (this.player.position.y >= oldZone.inner.topRight().y) {
                        this.player.network.loadingZone.translate(0.0f, 112.0f);
                    }
                    Network.MapTiles mapTiles = new Network.MapTiles();
                    Iterator<Vector2> it = this.player.network.loadingZone.diff(oldZone).iterator();
                    while (it.hasNext()) {
                        Vector2 position = it.next();
                        Tile tile = game.map.tiles.get(position);
                        if (tile != null) {
                            mapTiles.tiles.add(new Network.TileData(tile));
                            Tile tile2 = game.map.interiorTiles.get(game.map.interiorTilesIndex).get(position);
                            if (tile2 != null) {
                                mapTiles.tiles.add(new Network.TileData(tile2, game.map.interiorTilesIndex));
                            }
                            if (mapTiles.tiles.size() >= 14) {
                                game.server.sendToTCP(this.player.network.connectionId, mapTiles);
                                mapTiles.tiles.clear();
                            }
                            if (game.map.pokemon.containsKey(position)) {
                                game.server.sendToTCP(this.player.network.connectionId, new Network.OverworldPokemonData(game.map.pokemon.get(position), position));
                            }
                        }
                    }
                    game.server.sendToTCP(this.player.network.connectionId, mapTiles);
                    for (Player otherPlayer : game.players.values()) {
                        if (otherPlayer != this.player && this.player.network.loadingZone.contains(otherPlayer.position)) {
                            game.server.sendToTCP(this.player.network.connectionId, new Network.ServerPlayerData(otherPlayer));
                        }
                    }
                }
            }
            if (this.player.network.isRunning) {
                this.player.currSprite = new Sprite(this.player.standingSprites.get(this.player.dirFacing + "_running"));
            } else {
                this.player.currSprite = new Sprite(this.player.standingSprites.get(this.player.dirFacing));
            }
            if (this.player.network.tiles.get(this.player.position) == null || (!this.player.network.tiles.get(this.player.position).nameUpper.contains("door") && !this.player.network.tiles.get(this.player.position).name.contains("door"))) {
                if (this.player.network.shouldMove) {
                    game.actionStack.remove(this);
                    this.player.network.shouldMove = false;
                    if (this.player.network.dirFacing.equals("up")) {
                        this.player.dirFacing = "up";
                        newPos = new Vector2(this.player.position.x, this.player.position.y + 16.0f);
                    } else if (this.player.network.dirFacing.equals("down")) {
                        this.player.dirFacing = "down";
                        newPos = new Vector2(this.player.position.x, this.player.position.y - 16.0f);
                    } else if (this.player.network.dirFacing.equals("left")) {
                        this.player.dirFacing = "left";
                        newPos = new Vector2(this.player.position.x - 16.0f, this.player.position.y);
                    } else if (this.player.network.dirFacing.equals("right")) {
                        this.player.dirFacing = "right";
                        newPos = new Vector2(this.player.position.x + 16.0f, this.player.position.y);
                    }
                    Tile currTile = this.player.network.tiles.get(this.player.position);
                    Tile temp = this.player.network.tiles.get(newPos);
                    if (!this.player.dirFacing.equals("down") || currTile == null || !currTile.name.contains("rug")) {
                        String oppDir = "";
                        if (this.player.dirFacing.equals("up")) {
                            oppDir = "down";
                        } else if (this.player.dirFacing.equals("down")) {
                            oppDir = "up";
                        } else if (this.player.dirFacing.equals("right")) {
                            oppDir = "left";
                        } else if (this.player.dirFacing.equals("left")) {
                            oppDir = "right";
                        }
                        if (temp == null) {
                            game.insertAction(new PlayerBump(game, this.player));
                        } else if (temp.isSolid) {
                            game.insertAction(new PlayerBump(game, this.player));
                        } else if (!game.map.pokemon.containsKey(newPos) || game.map.pokemon.get(newPos).mapTiles != game.map.tiles) {
                            if (game.player.currFieldMove.equals("RIDE")) {
                                if (!temp.isLedge || (temp.ledgeDir().equals("up") && !this.player.dirFacing.equals("down"))) {
                                    if (currTile != null && currTile.isLedge && !currTile.ledgeDir().equals("up") && (currTile.ledgeDir().equals(this.player.dirFacing) || currTile.ledgeDir().equals(oppDir))) {
                                        game.insertAction(new PlayerLedgeJumpFast(game, this.player));
                                        return;
                                    }
                                } else if (temp.ledgeDir().equals(this.player.dirFacing) || temp.ledgeDir().equals(oppDir)) {
                                    game.insertAction(new PlayerLedgeJumpFast(game, this.player));
                                    return;
                                } else {
                                    game.insertAction(new PlayerBump(game, this.player));
                                    return;
                                }
                            }
                            if (currTile != null && currTile.isLedge && currTile.ledgeDir().equals("up") && this.player.dirFacing.equals("up")) {
                                game.insertAction(new PlayerLedgeJumpFast(game, this.player));
                            } else if (temp.isLedge && temp.ledgeDir().equals("up") && this.player.dirFacing.equals("down")) {
                                game.insertAction(new PlayerBump(game, this.player));
                            } else if (!temp.isLedge || temp.ledgeDir().equals("up")) {
                                if (this.player.network.isRunning) {
                                    game.insertAction(new PlayerRunning(game, this.player, this.alternate));
                                } else {
                                    game.insertAction(new PlayerMoving(game, this.player, this.alternate));
                                }
                                if (game.type == Game.Type.SERVER && (pokemon = checkWildEncounter(game, newPos)) != null) {
                                    this.player.setCurrPokemon();
                                    this.player.canMove = false;
                                    game.server.sendToTCP(this.player.network.connectionId, new Network.BattleData(pokemon));
                                    game.battles.put(this.player.network.id, new Battle());
                                    game.battles.get(this.player.network.id).oppPokemon = pokemon;
                                }
                            } else {
                                Tile fartherOutTile = game.map.tiles.get(newPos.cpy().add(newPos.cpy().sub(this.player.position)));
                                if (!temp.ledgeDir().equals(this.player.dirFacing) || (fartherOutTile != null && (fartherOutTile.isSolid || fartherOutTile.isLedge))) {
                                    game.insertAction(new PlayerBump(game, this.player));
                                } else {
                                    game.insertAction(new PlayerLedgeJump(game, this.player));
                                }
                            }
                        } else {
                            game.insertAction(new PlayerBump(game, this.player));
                        }
                    } else if (this.player.network.tiles == game.map.overworldTiles) {
                        this.player.network.tiles = game.map.interiorTiles.get(game.map.interiorTilesIndex);
                        game.insertAction(new PlayerMoving(game, this.player, this.alternate));
                    } else {
                        this.player.network.tiles = game.map.overworldTiles;
                        game.insertAction(new PlayerMoving(game, this.player, this.alternate));
                    }
                } else {
                    this.player.network.isRunning = false;
                }
            } else if (this.player.network.tiles == game.map.overworldTiles) {
                this.player.network.tiles = game.map.interiorTiles.get(game.map.interiorTilesIndex);
            } else {
                this.player.network.tiles = game.map.overworldTiles;
            }
        }
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        if (this.player == null) {
            this.player = game.player;
        }
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (this.player.isSleeping) {
            if (this.player.zsTimer < 64) {
                this.player.zSprite.setPosition(this.player.position.x + 8.0f, this.player.position.y + 18.0f);
            } else {
                this.player.zSprite.setPosition(this.player.position.x + 16.0f, this.player.position.y + 18.0f);
            }
            this.player.zsTimer++;
            if (this.player.zsTimer >= 128) {
                boolean outdoors = this.player.network.tiles == game.map.overworldTiles;
                if (this.player.type == Player.Type.LOCAL) {
                    outdoors = game.map.tiles == game.map.overworldTiles;
                }
                Iterator<Pokemon> it = this.player.pokemon.iterator();
                while (it.hasNext()) {
                    Pokemon pokemon = it.next();
                    if (!pokemon.isEgg) {
                        if (outdoors) {
                            pokemon.currentStats.put("hp", Integer.valueOf(pokemon.currentStats.get("hp").intValue() + ((int) Math.ceil((double) (((float) pokemon.maxStats.get("hp").intValue()) / 50.0f)))));
                        } else {
                            pokemon.currentStats.put("hp", Integer.valueOf(pokemon.currentStats.get("hp").intValue() + ((int) Math.ceil((double) (((float) pokemon.maxStats.get("hp").intValue()) / 25.0f)))));
                        }
                        if (this.player.sleepingDir != null) {
                            pokemon.currentStats.put("hp", Integer.valueOf(pokemon.currentStats.get("hp").intValue() + ((int) Math.ceil((double) (((float) pokemon.maxStats.get("hp").intValue()) / 15.0f)))));
                        }
                        if (pokemon.currentStats.get("hp").intValue() >= pokemon.maxStats.get("hp").intValue()) {
                            pokemon.currentStats.put("hp", pokemon.maxStats.get("hp"));
                            if (this.player.sleepingDir != null) {
                                pokemon.status = null;
                            }
                        }
                    }
                }
                this.player.zsTimer = 0;
            }
        }
        if (this.player.type == Player.Type.LOCAL) {
            localStep(game);
        } else if (this.player.type == Player.Type.REMOTE) {
            remoteStep(game);
        }
    }
}
